package com.zhuoshi.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zhuoshi.entity.Bargain;
import com.zhuoshi.entity.Indent;
import com.zhuoshi.entity.IndentCustom;
import com.zhuoshi.service.BargainService;
import com.zhuoshi.service.IndentService;

@Controller
@RequestMapping("indent")
public class IndentController {
	
	@Autowired
	private IndentService indentService;
	
	@Autowired BargainService bargainService;
	
	//查询所有订单
	@RequestMapping("selectAllIndentLiu")
	public ModelAndView selectAllIndentLiu() {
		List<IndentCustom> indents=indentService.selectAllIndentLiu();
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("indents", indents);
		modelAndView.setViewName("/Admin/second/dingDanChaXun.jsp");
		return modelAndView;
	}
	
	//添加合同信息
	@RequestMapping("quQianHeTongMessageLiu")
	public ModelAndView quQianHeTongMessageLiu(int id) {
		IndentCustom indentCustom=indentService.selectIndentCustomById(id);
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("indentCustom", indentCustom);
		modelAndView.setViewName("/Admin/second/addBargain.jsp");
		return modelAndView;
	}
	
	//去签合同（确认添加合同）
	@RequestMapping("quQianHeTongLiu")
	public String quQianHeTongLiu(Bargain bargain) throws Exception {
		int rows=bargainService.quQianHeTongLiu(bargain);
		if(rows>0) {
			return "redirect:/bargain/selectBargainList.action";
		}else {
			return "redirect:error.jsp";
		}		
	}
	
	//销售机会转认购  toJiHuiZhuanRenGou.action
			@RequestMapping("toJiHuiZhuanRenGou.action")
			public String toJiHuiZhuanRenGou(Indent indent) throws Exception{			
				
				int rows = indentService.toJiHuiZhuanRenGou(indent);	
				System.out.println("添加合同+++++"+rows);
				return "redirect:selectAllIndentLiu.action";
			}
}